<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>get Json Data</title>
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/json2.js"></script>
<script type="text/javascript" src="js/goeasy.js"></script>
<script type="text/javascript">
	function test(mq) {
		var u=JSON.parse(mq);
		
		var jsondata = u;
		
		var jsonString = JSON.stringify(jsondata);
		$
				.ajax({
					type : 'post',
					url : '${pageContext.request.contextPath}/elecStatus/updateData.action',
					dataType : 'json',
					data : {
						p : jsonString
					},
					success : function(data) {
						if(data==9){
							alert('设备数据更新成功！')
						}
					}

				})
	}

	function getMQ() {
        
		var goeasy = new GoEasy({
			appkey : '10a2c88a-15dc-4173-abe6-44c032543ca8',
		});
		goeasy.subscribe({
			channel : '666666',
			onMessage : function(result) {
				var a=JSON.parse(result.content);
				
				alert("接收到来自设备---("+a.name+")的一段json数据      :" + result.content);
				document.getElementById('equipname').innerHTML=a.name;
				document.getElementById('show').innerHTML=result.content;
				var re=result.content;
				test(re)
			}
		});
	}
	
	$(document).ready(function(){
		getMQ()
	})
	
</script>
</head>
<body>
	<h1>数据码头</h1>
	<p>能源管理系统平台接收到的json数据为：</p>
	<p>数据来自设备：<label id="equipname"></label></p>
	<p>数据信息：<label id="show"></label></p>
</body>
</html>